//
//  WXLStatusToolbar.swift
//  WXLWeoBo
//
//  Created by 王晓雷 on 16/6/30.
//  Copyright © 2016年 王晓雷. All rights reserved.
//

import SnapKit
import UIKit


class WXLStatusToolbar: UIView {
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    // MARK: --设置视图
   private func setupUI(){
        backgroundColor = RandomColor()
    //添加控件
        let retweetButton = addChildButtons("timeline_icon_retweet",title: "转发")
        let commenttButton = addChildButtons("timeline_icon_comment", title: "评论")
        let unlikeButton =  addChildButtons("timeline_icon_unlike", title: "赞")
    //分割线
    let line1 = addChildlines()
    let line2 = addChildlines()
    //添加约束
    retweetButton.snp_makeConstraints { (make) -> Void in
        make.top.leading.bottom.equalTo(self)
        make.width.equalTo(commenttButton)
    }
    commenttButton.snp_makeConstraints { (make) -> Void in
        make.top.bottom.equalTo(self)
        make.leading.equalTo(retweetButton.snp_trailing)
        make.width.equalTo(unlikeButton)
    }
    unlikeButton.snp_makeConstraints { (make) -> Void in
        make.top.bottom.trailing.equalTo(self)
        make.leading.equalTo(commenttButton.snp_trailing)
        
    }
    line1.snp_makeConstraints { (make) -> Void in
        make.centerY.equalTo(self)
        make.centerX.equalTo(retweetButton.snp_trailing)
    }
    line2.snp_makeConstraints { (make) -> Void in
        make.centerY.equalTo(self)
        make.centerX.equalTo(commenttButton.snp_trailing)
    }
    
    }
    //创建btn
    private func addChildButtons(imgName: String, title: String) -> UIButton{
        let button = UIButton()
        button.setImage(UIImage(named: imgName), forState: UIControlState.Normal)
        button.setTitle(title, forState:UIControlState.Normal)
        button.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(14)
        //设置背景图片
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: UIControlState.Highlighted)
        //添加控件
        addSubview(button)
        return button
        
    }
    
    private func addChildlines() -> UIImageView{
        let img = UIImageView(imgName: "timeline_card_bottom_line")
        //添加控件
        addSubview(img)
        return img
    }
    
}
